package LinkedList.合并有序链表;

import LinkedList.ListNode;

public class Test {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

        ListNode dummy = new ListNode(-1);
        ListNode cur = dummy;

        ListNode p1 = list1, p2 = list2;

        while(p1 != null && p2 != null) {
            if(p1.val >= p2.val) {
                cur.next = p2;
                p2 = p2.next;
            }else {
                cur.next = p1;
                p1 = p1.next;
            }
            cur = cur.next;
        }

        cur.next = p1 != null ? p1 : p2;

        return dummy.next;

    }
}
